﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SKYPE4COMLib;

namespace SkypeBot
{
    class Program
    {
        static void Main(string[] args)
        {
            var skype = new Skype();
            skype.Attach(5, true);

            foreach (var obj in skype.Chats)
            {
                IChat chat = (IChat)obj;
                Console.WriteLine("FriendlyName: [{0}] Name: [{1}]", chat.FriendlyName, chat.Name);
            }

            var annaChat = skype.CreateChatWith("gingerygreen");
            //annaChat.SendMessage("1");

            var config = BotConfig.GetSection();

            var rssStream = new RssStream(config.RssUrl);
            var items = rssStream.GetItems();

            var packetMaxDate = config.LastReadMessageDate;

            foreach(var item in items){
                if (config.LastReadMessageDate < item.PubDate)
                {
                    annaChat.SendMessage(item.ToString());
                    Console.WriteLine(item);
                    if (packetMaxDate < item.PubDate)
                    {
                        packetMaxDate = item.PubDate;
                    }
                }
                else
                {
                    config.LastReadMessageDate = packetMaxDate;
                }
            }

            config.Save();


            skype = null;
        }
    }
}
